<%@page import="javax.swing.text.DefaultStyledDocument"%>
<%@page import="com.liferay.portal.kernel.util.HtmlUtil"%>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@page import="com.liferay.portal.kernel.language.UnicodeLanguageUtil"%>
<%@page import="com.liferay.portal.kernel.servlet.SessionMessages"%>
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
<%@page import="com.liferay.portal.kernel.util.JavaConstants"%>
<%@page import="javax.portlet.PortletRequest"%>
<%@page import="com.liferay.portal.kernel.util.ListUtil"%>
<%@page
	import="com.bkav.portal.portlet.product.service.ProductLocalServiceUtil"%>
<%@page import="com.bkav.portal.portlet.product.model.Product"%>
<%@page
	import="com.bkav.portal.portlet.product.service.ProductCategoryLocalServiceUtil"%>
<%@page import="com.bkav.portal.portlet.product.model.ProductCategory"%>
<%@page import="java.util.List"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util"%>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"%>

<%@include file="/html/product/init.jsp"%>


<%
	List<ProductCategory> productCategoryList = ProductCategoryLocalServiceUtil
			.findAll();
%>
<liferay-portlet:renderURL var="productHomePageURL">
	<liferay-portlet:param name="jspPage" value="/html/product/view.jsp" />
</liferay-portlet:renderURL>


<aui:form method="post" action="<%=productHomePageURL%>">
		<aui:select name="categoryId" label="">
			<aui:option value="">Chọn chuyên mục</aui:option>
			<%
				for (ProductCategory productCategoryItem : productCategoryList) {
			%>
			<aui:option value="<%=productCategoryItem.getCategoryId()%>"><%=productCategoryItem.getCategoryName()%></aui:option>
			<%
				}
			%>
		</aui:select>
		<aui:input name="save" value="Search" type="submit" label=""/>
		<aui:button  value="Show all" label=""
			href="<%=productHomePageURL%>"/>
</aui:form>
<%
	long categoryId = ParamUtil.getLong(request, "categoryId");
	int productIndex = 0;
	List<Product> productListCategoryId = ProductLocalServiceUtil
			.findByCategory(categoryId);
	List<Product> productList = ProductLocalServiceUtil
			.findByGroup(groupId);
%>
<c:if test="<%=Validator.equals(categoryId, 0)%>">
	<liferay-ui:search-container emptyResultsMessage="no-entry-found">
		<liferay-ui:search-container-results
			results="<%=ListUtil.subList(productList,
							searchContainer.getStart(),
							searchContainer.getEnd())%>"
			total="<%=productList.size()%>" />
		<liferay-ui:search-container-row className="Product"
			keyProperty="productId" modelVar="Product">
			<%
				productIndex++;
			%>
			<liferay-portlet:renderURL var="defaultStyleHomePageURL">
				<liferay-portlet:param name="jspPage"
					value="/html/product/view_style/default_style.jsp" />
				<liferay-portlet:param name="productId"
					value="<%=String.valueOf(Product.getProductId())%>" />
			</liferay-portlet:renderURL>
			<liferay-ui:search-container-column-text name="#"
				value="<%=String.valueOf(productIndex)%>" />

			<liferay-ui:search-container-column-text name="Sản phẩm"
				value="<%=Product.getProductName()%>"
				href="<%=defaultStyleHomePageURL%>" />

		</liferay-ui:search-container-row>
		<liferay-ui:search-iterator paginate="<%=false%>" />
	</liferay-ui:search-container>
</c:if>


<c:if test="<%=categoryId != 0%>">
	<liferay-ui:search-container emptyResultsMessage="no-entry-found">
		<liferay-ui:search-container-results
			results="<%=ListUtil.subList(productListCategoryId,
							searchContainer.getStart(),
							searchContainer.getEnd())%>"
			total="<%=productCategoryList.size()%>" />
		<liferay-ui:search-container-row className="Product"
			keyProperty="productId" modelVar="product">
			<%
				productIndex++;
			%>
			<liferay-portlet:renderURL var="defaultStyleHomePageURL">
				<liferay-portlet:param name="jspPage"
					value="/html/product/view_style/default_style.jsp" />
				<liferay-portlet:param name="productId"
					value="<%=String.valueOf(product.getProductId())%>" />
				<liferay-portlet:param name="categoryId"
					value="<%=String.valueOf(product.getCategoryId())%>" />
			</liferay-portlet:renderURL>

			<liferay-ui:search-container-column-text name="#"
				value="<%=String.valueOf(productIndex)%>" />

			<liferay-ui:search-container-column-text name="Sản phẩm"
				value="<%=product.getProductName()%>"
				href="<%=defaultStyleHomePageURL%>" />


		</liferay-ui:search-container-row>
		<liferay-ui:search-iterator paginate="<%=false%>" />
	</liferay-ui:search-container>
</c:if>

<%
	long productId = ParamUtil.getLong(request, "productId");
	Product listProductId = ProductLocalServiceUtil
			.fetchProduct(productId);
%>
<c:if test="<%=(listProductId != null)%>">
	<h2>Thông tin sản phẩm</h2>
   Mã sản phẩm: <%=listProductId.getProductId()%></br>
   Tên sản phẩm: <%=listProductId.getProductName()%></br>
   Thông tin sản phẩm: <%=listProductId.getProductInfo()%></br>
</c:if>